﻿using System;
using System.Linq;
using Archie.Retail.Data;
using Archie.Retail.Data.SqliteStorage;

namespace Archie.Retail.TestStuff
{
    internal static class DataOperations
    {
        public static void DoTest()
        {
            var sdf = new SqliteDataManager();

            var r = sdf.GetDoors();

            if (!r.Any())
            {
                CredateTestData(sdf);
                r = sdf.GetDoors();
            }

            foreach (var door in r)
            {
                door.Article += "_123_";
                sdf.UpdateDoor(door);
            }
        }

        private static void CredateTestData(SqliteDataManager dataManager)
        {
            for (int i = 0; i < 3; i++)
            {
                var doorManufacturer = new DoorManufacturer(Guid.NewGuid(), "Произв " + i);
                dataManager.AddDoorManufacturer(doorManufacturer);

                var doorSeries = new DoorSeries(Guid.NewGuid(), "Door series " + i);
                dataManager.AddDoorSeries(doorSeries);

                var door = new Door(Guid.NewGuid(), "Дверь " + i, null, doorManufacturer.Id, doorSeries.Id);
                dataManager.AddDoor(door);

                var handleSeries = new HandleSeries(Guid.NewGuid(), "Серия ручки" + i);
                dataManager.AddHandleSeries(handleSeries);

                var handle = new Handle(Guid.NewGuid(), "Ручка" + i, null, handleSeries.Id);
                dataManager.AddHandle(handle);
            }
        }
    }
}
